/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.latesis.dao.hibernate;

import com.latesis.bean.AsignacionServicioBean;
import com.latesis.dao.AsignacionServicioDAO;
import com.latesis.dao.MensajeDAO;
import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author acabrera
 */
@Transactional(propagation=Propagation.SUPPORTS)
public class AsignacionServicioDAOHibernateImpl extends HibernateDaoSupport implements AsignacionServicioDAO{
     public AsignacionServicioBean guardar(AsignacionServicioBean bean) {
         getHibernateTemplate().saveOrUpdate(bean);
         return bean;
    }

    public void borrar(AsignacionServicioBean bean) {
        getHibernateTemplate().delete(bean);
    }

    public AsignacionServicioBean buscar(AsignacionServicioBean bean) {
        
        return getHibernateTemplate().get(AsignacionServicioBean.class, bean.getId());
    }

    public List<AsignacionServicioBean> buscarTodos() {
        return (List<AsignacionServicioBean>)getHibernateTemplate().find("from AsignacionServicioBean ");
    }

    public AsignacionServicioBean buscar(long idServicio, long idChofer, long idMovil) {
        List list = getHibernateTemplate().find(
                      "from AsignacionServicioBean a where a.chofer.id=? and a.movil.id=? and a.servicio.id=?",idChofer,idMovil,idServicio
                );
	return list.isEmpty()?null:(AsignacionServicioBean)list.get(0);
    }
    
}
